import hashlib  
import time  
import secrets  
import string  
  
def generate_random_string(length=6):  
    """生成一个指定长度的随机字符串"""  
    letters_and_digits = string.ascii_letters + string.digits  
    return ''.join(secrets.choice(letters_and_digits) for _ in range(length))  
  
def generate_signature(appid):  
    """生成包含SHA-256加密后的APPID、时间戳和随机字符串的拼接字符串"""  
    # 对APPID进行SHA-256加密  
    sha256_appid = hashlib.sha256(appid.encode()).hexdigest()  
    # 获取当前时间戳（固定到秒）  
    timestamp = str(int(time.time()))  
    # 生成随机6位字符串  
    random_str = generate_random_string(6)  
    # 拼接字符串  
    signature = sha256_appid + timestamp + random_str  
    return signature  
  
# 示例  
appid = "your_appid_here"  
signature = generate_signature(appid)  
print(f"Generated Signature: {signature}")